#!/usr/bin/env python

from astpychannel import Channel
from astpydb import PersistData

import unittest

class TestAstpyChannel (unittest.TestCase):
	
	def setUp(self):
		self.channel = Channel("SIP/test-dfe92")
	
	def testGetName(self):
		self.assertEqual(self.channel.getName(), "test")
	def testGetTech(self):
		self.assertEqual(self.channel.getTech(), "SIP")
	def testGetRandom(self):
		self.assertEqual(self.channel.getRandom(), "dfe92")
	def testGetChannel(self):
		self.assertEqual(self.channel.getChannel(), "SIP/test")
	def testGetUniqueChannel(self):
		self.assertEqual(self.channel.getUniqueChannel(), "SIP/test-dfe92")
	
class TestPersistData (unittest.TestCase):
	
	def setUp(self):
		self.pd = PersistData("localhost", "root", "passw0rd", "asterisk")
	
	def testSingleton(self):
		tmp = PersistData()
		self.assertEqual(self.pd.dbhost, "localhost")
		self.assertEqual(self.pd.dbuser, "root")
		self.assertEqual(self.pd.dbpass, "passw0rd")
		self.assertEqual(self.pd.dbhost, tmp.dbhost)
		self.assertEqual(self.pd.dbpass, tmp.dbpass)
		self.assertEqual(self.pd.dbuser, tmp.dbuser)


suite = unittest.TestLoader().loadTestsFromTestCase(TestAstpyChannel)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestPersistData))
res = unittest.TextTestRunner(verbosity=2).run(suite)
